//
//  FindBlueViewController.m
//  project
//
//  Created by 圆圆陈 on 2017/12/15.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "FindBlueViewController.h"
#import "BlueToothViewController.h"
#import "SNEquipmentViewController.h"

@interface FindBlueViewController ()
{
    UIView *backView;
    UILabel *label;
}
@end

@implementation FindBlueViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
    [tabBar hiddenTheTabBarView];
//    if (KK_BLEConnect.model.isConnected) { // 手环绑定界面
//        SNEquipmentViewController *equipVC = [[SNEquipmentViewController alloc]init];
//        [self.navigationController pushViewController:equipVC animated:NO];
//    }
    
    [self updateStateV];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
//    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
//    }
}

- (void)updateModel:(KKBLEModel *)model type:(KKBLEUpdateType)type {
    
    
    if (KK_BLEConnect.model.isConnected) { // 手环绑定界面
//        SNEquipmentViewController *equipVC = [[SNEquipmentViewController alloc]init];
//        [self.navigationController pushViewController:equipVC animated:NO];
//        [self.navigationController popViewControllerAnimated:NO];
    }
    
    [self updateStateV];
}

- (void)updateStateV
{
    if (SN_PublicClass.isBoind) {
        if (KK_BLEConnect.isConnected) {
            label.text = [NSString stringWithFormat:@"%@ %@", KK_BLEModel.bleName, HHH_Text(@"已连接")];
        }
        else
        {
            label.text = [NSString stringWithFormat:@"%@ %@", KK_BLEModel.bleName, HHH_Text(@"设备未连接")];
        }
        
    } else {
        label.text = HHH_Text(@"未绑定设备，请先绑定手环");
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColorHEX(0xf0f2f5);

    UIView *bgView = [[UIView alloc]init];
    bgView.frame = SNFRAME(0, 0, screenWidth, FitSimpleIpx(64, 88));
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    
    UIButton *leftButton = [[UIButton alloc] init];
    leftButton.frame = CGRectMake(5, 20+FitSimpleIpx(0, 20), 44, 44);
    [leftButton setImageNormal:@"进入"];
    [leftButton addTarget:self action:@selector(leftbuttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), screenWidth, 44)];
    lable.textColor     = UIColorHEX(0x161616);
    lable.font          = SNFONTMEDIUM(17);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text          = HHH_Text(@"设备");
    [self.view addSubview:lable];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = SNFRAME(screenWidth/2 - 45, bgView.bottom +112, 90, 90);
    imageView.image = [UIImage imageNamed:@"形状结合"];
//    imageView.backgroundColor = UIColorHEX(0xe4e4e4);
    [self.view addSubview:imageView];
    
    label = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView.bottom+25, screenWidth,22)];
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 0;
    label.textColor = UIColorHEX(0x96969F);
    label.font          = [UIFont systemFontOfSize:FitFont(17)];
    [self.view addSubview:label];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitleNormal:HHH_Text(@"扫描手环1")];
    btn.backgroundColor = UIColorHEX(0xFFF7A00);
    btn.layer.cornerRadius = 6;
    btn.titleLabel.textColor = UIColorHEX(0xFFFfff);
    btn.frame           = CGRectMake(screenWidth/2 - 90, label.bottom +45, 180,40);
    btn.titleLabel.font = [UIFont systemFontOfSize:FitFont(17)];
    [btn addTouchUpTarget:self action:@selector(pushToBlueVC)];
    [self.view addSubview:btn];
    
    
//    UIImage     *backImage     = UIImageNamed(@"背景");
//    UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), HHHWIDTH, HHHWIDTH*backImage.size.height/backImage.size.width)];
//    backImageView.userInteractionEnabled = YES;
//    backImageView.image                  = backImage;
////    [self.view addSubview:backImageView];
//    CGFloat height = 20+FitSimpleIpx(0, 20)+44+backImageView.bottom;
//    backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, HHHWIDTH*2/3, HHHHEIGHT/6)];
//    backView.center             = CGPointMake(self.view.center.x, height+15);
//    backView.layer.cornerRadius = 10;
//    backView.clipsToBounds      = YES;
//    backView.layer.borderColor  = SNCOLORGRAY.CGColor;
//    backView.layer.borderWidth  = 1;
//    backView.backgroundColor = [UIColor yellowColor];
//    [self.view addSubview:backView];
    
//    label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, backView.width, backView.height*2/3)];
//    label.textAlignment = NSTextAlignmentCenter;
//    label.numberOfLines = 0;
//    label.font          = [UIFont systemFontOfSize:FitFont(17)];
//    [backView addSubview:label];
    
//    UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(0, backView.height*2/3, backView.width, 2)];
//    line.backgroundColor = SNCOLORSEPRATE;
//    [backView addSubview:line];
//
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [btn setTitleNormal:HHH_Text(@"扫描手环1")];
//    [btn setTitleColorNormal:SNCOLORGRAY];
//    btn.frame           = CGRectMake(0, backView.height*2/3+2, backView.width, backView.height/3-2);
//    btn.titleLabel.font = [UIFont systemFontOfSize:FitFont(17)];
//    [btn addTouchUpTarget:self action:@selector(pushToBlueVC)];
//    [backView addSubview:btn];
    

}

- (void)pushToBlueVC {
    BlueToothViewController *blueVC = [[BlueToothViewController alloc]init];
    CustomTabBar            *tabBar = (CustomTabBar *)self.tabBarController;
    
    blueVC.type = 1;
    [tabBar hiddenTheTabBarView];
    [self.navigationController pushViewController:blueVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (void)leftbuttonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end

